package future;

import java.util.concurrent.*;

public class FutureMain {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> task = new FutureTask<String>(new RealData("b"));

        ExecutorService service = Executors.newFixedThreadPool(1);
        service.submit(task);
        System.out.println("任务提交完毕    ");
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("开始获取    ");
        System.out.println("任务是否完成： " + task.isDone());
//        task.cancel(false);
        try {
            System.out.println("数据 = " + task.get(900, TimeUnit.MILLISECONDS));
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
        System.out.println("获取完毕    ");
    }
}
